
package global.com.loansapplication.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.superrecycleview.superlibrary.adapter.BaseViewHolder;
import com.superrecycleview.superlibrary.adapter.SuperBaseAdapter;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import global.com.loansapplication.R;
import global.com.loansapplication.bean.ClueInfo;
import global.com.loansapplication.comm.Constants;
import global.com.loansapplication.ui.actviity.user.CustomAct;
import global.com.loansapplication.ui.widget.flowlayout.FlowLayout;
import global.com.loansapplication.ui.widget.flowlayout.TagAdapter;
import global.com.loansapplication.ui.widget.flowlayout.TagFlowLayout;
import global.com.loansapplication.util.StringUtils;
import global.com.loansapplication.util.SysUtils;

/**
 * chenjian
 */
public class OwnAdapter extends SuperBaseAdapter<ClueInfo> {
    Context mContext;
    List<String> strings = new ArrayList<>();
    /**
     * 是否是自定义线索
     */
    boolean mIsCustom = false;

    public OwnAdapter(Context context, List<ClueInfo> data) {
        super(context, data);
        mContext = context;
        strings.add("工作狂");
        strings.add("大美女");
        strings.add("工作狂");


    }

    public OwnAdapter(Context context, List<ClueInfo> data, boolean isCustom) {
        super(context, data);
        mContext = context;
        mIsCustom = isCustom;
    }

    @Override
    protected void convert(BaseViewHolder holder, final ClueInfo item, final int position) {
        String info = (StringUtils.isEmpty(item.getCity()) ? "" : item.getCity()) + (StringUtils.isEmpty(item.getZhiye()) ? "" : " |" + item.getZhiye()) + ((item.getShouru() == 0) ? "" : "  |月收入" + item.getShouru());
        holder.setText(R.id.item_collection_name, item.getName()).setText(R.id.item_collection_phone, item.getMobile()).
                setText(R.id.item_collection_money, item.getPrice() + "").setText(R.id.item_collection_city, info).
                setText(R.id.item_collection_dai_time, "贷款期限 " + item.getMonth() + "个月").setText(R.id.item_collection_time, "更新时间：" + SysUtils.getDatePoorNew(new Date(), item.getUpdateTime()));

        TextView state = holder.getView(R.id.item_collection_state);
        state.setText("查看详情");
        state.setBackgroundResource(R.drawable.bg_shape_red);
        state.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, CustomAct.class);
                intent.putExtra("position", position + "");
                intent.putExtra(Constants.KEYSTRING, item.getStudentCode());
                intent.putExtra("isCustom", mIsCustom);
                intent.putExtra("userPhone", item.getMobile());
                mContext.startActivity(intent);
            }
        });
        String[] lable = item.getLabel().split("；");

        TagFlowLayout FlowTagLayout = holder.getView(R.id.item_collection_tip);
        if (StringUtils.isEmpty(item.getLabel())) {
            FlowTagLayout.setVisibility(View.GONE);
        }
        FlowTagLayout.setAdapter(new TagAdapter<String>(lable) {
            @Override
            public View getView(FlowLayout parent, int position, String s) {
                TextView view = (TextView) LayoutInflater.from(mContext).inflate(R.layout.tag_item, null);
                view.setText(s);
                return view;
            }
        });

        holder.getView(R.id.item_collection_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, CustomAct.class);
                intent.putExtra("position", position + "");
                intent.putExtra(Constants.KEYSTRING, item.getStudentCode());
                intent.putExtra("isCustom", mIsCustom);
                intent.putExtra("userPhone", item.getMobile());
                mContext.startActivity(intent);
            }
        });

    }

    @Override
    protected int getItemViewLayoutId(int position, ClueInfo item) {
        return R.layout.item_own;
    }

    @Override
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {

    }


}